<extend name="Common@Base/layout"/>
<block name="body">
    <div class="pside">
        <include file="Common@Public/psidemenu"/>
    </div>
    <div class="pside-toggle pside-hide"><i class="fa fa-angle-double-left"></i></div>
    <form id="paging_form" name="paging_form" method="get" action="/custom/index/index">
        <div class="pmain">
            <div class="main-content main-pagebar-content">
                <div class="container-fluid">
                    <div class="row">
                        <div class="col-sm-12">
                            <h3 class="mod-title">
                                <span class="t">客户管理</span>
                            </h3>
                            <div class="panel panel-default">
                                <div class="panel-body panel-body-up-table">
                                    <div class="search-panel">
                                        <div class="search">
                                            <div class="dropdown btn-group">
                                                <a class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                                    <span id="search_type_name" class="option-name">客户类型</span> <i class="fa fa-angle-down"></i></a>
                                                <ul class="dropdown-menu dropdown-option-menu">
                                                    <li><a data-value="" role="button">客户类型</a></li>
                                                    <volist name="Custom_Type" id="custom_type">
                                                        <li><a data-value="{$key}" role="button">{$custom_type}</a></li>
                                                    </volist>
                                                </ul>
                                                <input id="search_type" name="search_type" class="option-value filter-item-value" type="hidden"
                                                       value="{$_page->parameter['search_type']}">
                                            </div>
                                            <div class="dropdown btn-group">
                                                <a class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                                    <span id="search_distribute_name" class="option-name">状态</span> <i class="fa fa-angle-down"></i></a>
                                                <ul class="dropdown-menu dropdown-option-menu">
                                                    <li><a data-value="" role="button">全部</a></li>
                                                    <li><a data-value="0" role="button">未分配</a></li>
                                                    <li><a data-value="1" role="button">已分配</a></li>
                                                </ul>
                                                <input id="search_distribute" name="search_distribute" class="option-value filter-item-value" type="hidden"
                                                       value="{$_page->parameter['search_distribute']}">
                                            </div>

                                            <div class="btn-group">
                                                <input name="search_key" type="text" class="form-control" value="{$_page->parameter['search_key']|urldecode}"
                                                       placeholder="请输入客户名">
                                            </div>
                                            <div class="btn-group">
                                                <button type="submit" class="btn btn-primary">搜索</button>
                                            </div>
                                        </div>

                                        <div class="select-group">
                                            <a class="btn btn-operate-link" role="button" data-toggle="modal" data-target="#edit-custom"
                                               data-type="new-custom">添加客户</a>
                                        </div>
                                    </div>

                                </div>
                                <div class="table-responsive">

                                    <table class="table-check table-link-hover table table-striped table-bordered table-hover">
                                        <thead>
                                        <tr>
                                            <th style="width: 80px;">优先级</th>
                                            <th>公司名称</th>
                                            <th>目标产品</th>
                                            <!--<th>电话</th>-->
                                            <!--<th>传真</th>-->
                                            <th>公司地址</th>
                                            <th>行业</th>
                                            <th>状态</th>
                                            <th>跟踪人</th>
                                            <th>添加人</th>
                                            <th></th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <volist name="custom_list" id="custom">
                                            <tr data-customid="{$custom.id}"
                                                data-name="{$custom.name}"
                                                data-tel="{$custom.tel}"
                                                data-fax="{$custom.fax}"
                                                data-address="{$custom.address}"
                                                data-type="{$custom.type}"
                                                data-remark="{$custom.remark}"
                                                data-trade="{$custom.trade}"
                                                data-target_product="{$custom.target_product}"
                                                data-source="{$custom.source}"
                                            >
                                                <td>{$custom.priority|fc_config_name_by_key="Custom_Activity_Priority",###}</td>
                                                <td><a target="_blank" href="/custom/index/detail?id={$custom.id}">{$custom.name}.</a></td>
                                                <td>{$custom.target_product|fc_config_name_by_key="Custom_Target_Product",###}</td>
                                                <!--<td>{$custom.tel}</td>-->
                                                <!--<td>{$custom.fax}</td>-->
                                                <td>{$custom.address}</td>
                                                <td>{$custom.trade|fc_config_name_by_key="Custom_Trade",###}</td>
                                                <td>{$custom.state|fc_config_name_by_key="Custom_State",###}</td>
                                                <td>{$custom.leader_user_id|fc_get_user_name}</td>
                                                <td>{$custom.add_user_id|fc_get_user_name}</td>
                                                <td class="td-action">
                                                    <if condition="fa_has_auth($custom['add_user_id'])">
                                                    <a class="td-btn" data-toggle="modal" data-target="#edit-custom" data-type="edit-info" role="button">编辑</a>
                                                    <a class="td-btn" data-type="delete-info" role="button">删除</a>
                                                    </if>
                                                </td>
                                            </tr>
                                        </volist>
                                        </tbody>
                                    </table>
                                    <input class="checked-item" type="hidden">
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="main-pagebar">
                <include file="Common@Public/paging"/>
            </div>
        </div>
    </form>
    <include file="Index/Public/edit"/>
    <include file="Index/Public/script"/>
    <script>
        $(document).ready(function () {
            $("#allot-custom").click(function () {
//                var data = $("#paging_form").serialize();
                var data = 'id=1';
                var href = '/custom/index/allot?todo=2&' + data;
                $.colorbox({href: href});
            });

            var vx = $("#search_type").val();
            if (vx != "") {
                $("#search_type").prev().find('a').each(function () {
                    var $this = $(this);
                    if ($this.data('value') == vx) {
                        $("#search_type_name").text($this.text());
                    }
                });
            }
            var vx = $("#search_distribute").val();
            if (vx != "") {
                $("#search_distribute").prev().find('a').each(function () {
                    var $this = $(this);
                    if ($this.data('value') == vx) {
                        $("#search_distribute_name").text($this.text());
                    }
                });
            }
            $('a[data-type="delete-info"]').click(function () {
                var $tr = $(this).parent().parent();
                alertify.confirm("确定操作？", function (e) {
                    if (e) {
                        var url = "/custom/index/delete";
                        var data = "id=" + $tr.attr('data-customid');
                        $.ajax({
                            type: "GET",
                            url: url,
                            data: data,
                            success: function (data) {
                                if (data == "0") {
                                    alertify.alert("操作成功!", function () {
                                        location.reload();
                                    });

                                } else {
                                    alertify.alert("操作失败!");
                                }
                            }
                        });
                    }
                });
            });
        });
    </script>
</block>